package com.brillilab.service.core.message.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.common.entity.PageVo;
import com.brillilab.common.utils.MyBeanUtils;
import com.brillilab.dao.mapper.message.EventAuditMapper;
import com.brillilab.domain.enums.common.BoolEnum;
import com.brillilab.domain.po.message.EventAudit;
import com.brillilab.domain.po.message.Message;
import com.brillilab.service.core.message.IEventAuditService;
import com.brillilab.service.module.message.template.enums.MessageTypeEnum;
import com.github.pagehelper.PageHelper;

@Service
@Transactional
@Deprecated
public class EventAuditServiceImpl implements IEventAuditService {

    @Resource
    private EventAuditMapper eventAuditMapper;

	@Override
	public void insert(Message message) {
	
		if(MessageTypeEnum.NotLabPIAddMember.getValue().equals(message.getType())
				|| MessageTypeEnum.RegisterSuccess.getValue().equals(message.getType())
				|| MessageTypeEnum.ReceiveMemberRecommendMethod.getValue().equals(message.getType())
				|| MessageTypeEnum.NotLeaderOrPIAddTopicMember.getValue().equals(message.getType()) ) {
			EventAudit eventAudit = MyBeanUtils.copyBean(message, EventAudit.class);
			eventAudit.setId(null);
			eventAuditMapper.insert(eventAudit);
		}
	}

	@Override
	public PageVo<EventAudit> getEventAuditList(Long labId, Long labMemberId, int pageNum,int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<EventAudit> list = eventAuditMapper.selectEventAuditList(labId, labMemberId);
		return new PageVo<EventAudit>(list);
	}

	@Override
	public void audit(MessageTypeEnum typeEnum, Long referId, Long labId) {
		LambdaQueryWrapper<EventAudit> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(EventAudit::getType, typeEnum.getValue());
		queryWrapper.eq(EventAudit::getLabId, labId);
		queryWrapper.eq(EventAudit::getReferId, referId);
		queryWrapper.eq(EventAudit::getIsAudit, BoolEnum.FALSE.getValue());
		EventAudit message = new EventAudit();
		message.setIsAudit(BoolEnum.TRUE.getValue());
		eventAuditMapper.update(message, queryWrapper);
	}

	@Override
	public List<EventAudit> getEventAuditList(List<Integer> typeEnums) {
		LambdaQueryWrapper<EventAudit> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(EventAudit::getIsAudit, BoolEnum.FALSE.getValue());
		queryWrapper.in(EventAudit::getType, typeEnums);
		return eventAuditMapper.selectList(queryWrapper);
	}
	
	@Override
	public void updateById(EventAudit eventAudit) {
		eventAuditMapper.updateById(eventAudit);
	}

    
}
